home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / comms / other / ascan / sources / ddelay.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  2KB  |  78 lines

  1.  
  2. #include "ascan.h"
  3. #include <proto/timer.h>
  4.  
  5. /***************************************************************************/
  6. /* delay functions using timer.device, not so much to say*/
  7.  
  8. LONG setDStruct(struct dstruct *ds)
  9. {
  10.     if ((ds->sigBit=AllocSignal(-1))==-1)
  11.         return FALSE;
  12.  
  13.     INITPORT(&ds->dport,ds->sigBit);
  14.     INITMESSAGE(MESSAGE(&ds->dtr),&ds->dport,sizeof(struct timerequest));
  15.  
  16.     if (OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest*)&ds->dtr,0)) {
  17.         FreeSignal(ds->sigBit);
  18.         ds->sigBit=-1;
  19.         return FALSE;
  20.     }
  21.  
  22.     ds->flags = DSFLG_ALLOCATED;
  23.     return TRUE;
  24. }
  25.  
  26. /***************************************************************************/
  27.  
  28. void freeDStruct(struct dstruct *ds)
  29. {
  30.     if (ds->flags & DSFLG_ALLOCATED) {
  31.         if (ds->flags & DSFLG_ACTIVE) stopDelay(ds);
  32.         CloseDevice((struct IORequest *)&ds->dtr);
  33.         FreeSignal(ds->sigBit);
  34.         ds->flags &= ~DSFLG_ALLOCATED;
  35.     }
  36. }
  37.  
  38. /***************************************************************************/
  39.  
  40. ULONG doDelay(struct dstruct *ds,ULONG secs,ULONG micros,ULONG signals)
  41. {
  42.     register ULONG rec;
  43.  
  44.     ds->dtr.tr_node.io_Command = TR_ADDREQUEST;
  45.     ds->dtr.tr_time.tv_secs    = secs;
  46.     ds->dtr.tr_time.tv_micro   = micros;
  47.     SendIO((struct IORequest *)&ds->dtr);
  48.     rec = Wait((1<<ds->sigBit)|signals);
  49.     AbortIO((struct IORequest *)&ds->dtr);
  50.     WaitIO((struct IORequest *)&ds->dtr);
  51.  
  52.     return rec;
  53. }
  54.  
  55. /***************************************************************************/
  56.  
  57. void startDelay(struct dstruct *ds,ULONG secs,ULONG micros)
  58. {
  59.     ds->flags |= DSFLG_ACTIVE;
  60.     ds->dtr.tr_node.io_Command = TR_ADDREQUEST;
  61.     ds->dtr.tr_time.tv_secs    = secs;
  62.     ds->dtr.tr_time.tv_micro   = micros;
  63.     SendIO((struct IORequest *)&ds->dtr);
  64. }
  65.  
  66. /***************************************************************************/
  67.  
  68. void stopDelay(struct dstruct *ds)
  69. {
  70.     if (ds->flags & DSFLG_ACTIVE) {
  71.         AbortIO((struct IORequest *)&ds->dtr);
  72.         WaitIO((struct IORequest *)&ds->dtr);
  73.         ds->flags &= ~DSFLG_ACTIVE;
  74.     }
  75. }
  76.  
  77. /***************************************************************************/
  78.